<?php
/**
 * Groups module for XOOPS
 *
 * You may not change or alter any portion of this comment or credits
 * of supporting developers from this source code or any supporting source code 
 * which is considered copyrighted (c) material of the original comment or credit authors.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @copyright       The Groups Project http://code.google.com/p/groupsforxoops/
 * @license         http://www.fsf.org/copyleft/gpl.html GNU public license
 * @package         groups
 * @since           2.3.0
 * @author          Hui Xiao < xh.8326@gmail.com >
 * @version         $Id: functions.php Sat Jul 18 13:06:58 CST 2009
 */

if ( !defined("XOOPS_ROOT_PATH") ) exit;


function xoops_groups_confirm($hiddens, $action, $msg, $submit = '', $addtoken = true){
    $submit = ($submit != '') ? trim($submit) : _SUBMIT;
    $val = "";
    $val .= '<div class="confirmMsg">' . $msg . '<br />
      <form method="post" action="' . $action . '">
    ';
    foreach ($hiddens as $name => $value) {
        if (is_array($value)) {
            foreach ($value as $caption => $newvalue) {
                $val .= '<input type="radio" name="' . $name . '" value="' . htmlspecialchars($newvalue) . '" /> ' . $caption;
            }
            $val .= '<br />';
        } else {
            $val .= '<input type="hidden" name="' . $name . '" value="' . htmlspecialchars($value) . '" />';
        }
    }
    if ($addtoken != false) {
        $val .= $GLOBALS['xoopsSecurity']->getTokenHTML();
    }
    $val .= '
        <input type="submit" name="confirm_submit" value="' . $submit . '" title="' . $submit . '"/> <input type="button" name="confirm_back" value="' . _CANCEL . '" onclick="javascript:history.go(-1);" title="' . _CANCEL . '" />
      </form>
    </div>
    ';
    return $val;
}

function xoops_groups_ajax_confirm($hiddens, $action, $msg, $submit = '', $addtoken = true){
    $submit = ($submit != '') ? trim($submit) : _SUBMIT;
    $val = "";
    $val .= '<div class="confirmMsg">' . $msg . '
      <form method="post" action="' . $action . '">
    ';
    foreach ($hiddens as $name => $value) {
        if (is_array($value)) {
            foreach ($value as $caption => $newvalue) {
                $val .= '<input type="radio" name="' . $name . '" value="' . htmlspecialchars($newvalue) . '" /> ' . $caption;
            }
            $val .= '<br />';
        } else {
            $val .= '<input type="hidden" name="' . $name . '" value="' . htmlspecialchars($value) . '" />';
        }
    }
    if ($addtoken != false) {
        $val .= $GLOBALS['xoopsSecurity']->getTokenHTML();
    }
    $val .= '
    <br/>
    <input type="submit" name="confirm_submit" value="' . $submit . '" title="' . $submit . '"/></form>
    </div>
    ';
    return $val;
}



function groups_getTopicHighlight($highlight_val,$subject) {
	if ( empty($highlight_val) )return $subject;
	$row = explode("#",$highlight_val);
	if ( $row["0"] > 7 ) {
		return $subject;
	}
	$font_type_val = $row["0"];
    $str = "<font style='";
    $str_type = "";
    
    if ( $font_type_val == 1 ) {
    	$str_type = "text-decoration: underline;";
    }
    if ( $font_type_val == 2 ) {
    	$str_type = "font-style: italic;";
    }
    if ( $font_type_val == 3 ) {
    	$str_type = "text-decoration: underline; font-style: italic;";
    }
    if ( $font_type_val == 4 ) {
    	$str_type = "font-weight: bold;";
    }
    if ( $font_type_val == 5 ) {
    	$str_type = "text-decoration: underline;font-weight: bold;";
    }
    if ( $font_type_val == 6 ) {
    	$str_type = "font-style: italic; font-weight: bold;";
    }
    if ( $font_type_val == 7 ) {
    	$str_type = "text-decoration: underline;font-style: italic; font-weight: bold;";
    }
    $str .= $str_type;
    
    $color_val = "#".$row["1"] ;
    if ( preg_match("/^#[0-9a-fA-F]{6}$/", $color_val )){
        $str .= "color: ".$color_val; 
    } 
    
    $str .= "'>" .$subject . "</font>";
    
    return $str;
}
function filterString($string, $pattern = "",$color="#ff00ff")
{
	if(empty($string)) return;
	$patterns = array();
	$replacements = array();
	if(is_array($pattern) && count($pattern)>0){
		foreach($pattern as $pat){
			if(!in_array($pat, $patterns)){
				$patterns[] = '/'.$pat.'/';
				$replacements[] = "<font style=\"background-color:{$color};\">{$pat}</font>";
			}
		}
	}
	$string = preg_replace($patterns, $replacements, $string);
	return $string;
}
